let db = require("../db/index");
 
// 社区管理列表查询
exports.community = (req, res) => {
    var sql =
        `select * from communitymanagement`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 社区管理按条件查询
exports.communityselect = (req, res) => {
    var sql =
        `SELECT * FROM communitymanagement where name="${req.query.name}"`;
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 社区管理添加社区
exports.communityadd = (req, res) => {
    var sql =
        `insert into communitymanagement(name,Numberofbuildings,area,detailedAddress,chargeperson,chargepersonphone,edit,operte,del,coveranarea,buildingarea,Publicarea,afforestedarea,fixedtelephone,imageUrl,textarea)values('${req.query.name}',${req.query.Numberofbuildings},'${req.query.area}','${req.query.detailedAddress}','${req.query.chargeperson}','${req.query.chargepersonphone}','编辑','楼宇管理','删除','${req.query.coveranarea}','${req.query.buildingarea}','${req.query.Publicarea}','${req.query.afforestedarea}','${req.query.fixedtelephone}','${req.query.imageUrl}','${req.query.textarea}');`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
// 社区管理列表分页器
exports.communitypage = (req, res) => {
    var sql =
        `select * from communitymanagement limit ${req.query.currentpage*req.query.pagelimit},${req.query.pagelimit}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 社区管理列表编辑查询
exports.communityedit = (req, res) => {
    var sql =
        `select * from communitymanagement where date=${req.query.data}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 删除列表中的某一位
exports.communitydel = (req, res) => {
    var sql =
        `delete  FROM communitymanagement where date=${req.query.data}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 社区管理中的数据修改
exports.communitychange = (req, res) => {
    var sql =
        `update communitymanagement set name='${req.query.name}',Numberofbuildings=${req.query.Numberofbuildings},area='${req.query.area}',detailedAddress='${req.query.detailedAddress}',chargeperson='${req.query.chargeperson}',chargepersonphone='${req.query.chargepersonphone}',coveranarea='${req.query.coveranarea}',buildingarea='${req.query.buildingarea}',Publicarea='${req.query.Publicarea}',afforestedarea='${req.query.afforestedarea}',fixedtelephone='${req.query.fixedtelephone}',imageUrl='${req.query.imageUrl}',textarea='${req.query.textarea}' where date=${req.query.date}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};